﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain.Repositories;
using Domain.Enums;
using Domain.Exceptions;

namespace Domain.Entities
{
    public class Question:IEntity
    {
        public virtual int Id { get; set; }
        public virtual string MediaData { get; set; }
        public virtual IEnumerable<Answer> Answers { get; set; }
        public virtual Chapter Chapter { get; set; }

        public virtual QuestionType GetQuestionType()
        {
            if (Answers.Count() == 1)
            {
                return QuestionType.open;
            }
            else if (Answers.Count(x => x.Correctness) == 1)
            {
                return QuestionType.radio;
            }
            else if (Answers.Count(x => x.Correctness) > 1)
            {
                return QuestionType.check;
            }
            else
            {
                throw new AnswerGenerationException("Exception of question parameters (perhaps incorrect number of right answers).");
            }
        }
    }
}
